/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef NODECPP_CRYPTO_SHA1_H_
#define NODECPP_CRYPTO_SHA1_H_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <string>
#include <cstdint>
#include <openssl/sha.h>
#include <openssl/crypto.h>
#include <NodeCpp/Macros.h>

namespace NodeCpp {
namespace Crypto {
    class BigNumber;
    
    class Sha1Hash
    {
    public:
    	Sha1Hash(void);
    	~Sha1Hash(void);
    
    public:
    	void Initialize(void);
    	void Finalize(void);
    
    	void UpdateBigNumbers(BigNumber*, ...);
    	void UpdateData(const std::uint8_t*, std::size_t);
    	void UpdateData(const std::string&);
    
        const std::uint8_t* digest(void) const { return &Digest_[0]; }
    	int length(void) const { return SHA_DIGEST_LENGTH; }
    
    private:
    	SHA_CTX         Ctx_;
    	std::uint8_t    Digest_[SHA_DIGEST_LENGTH];
    	DISALLOW_COPY_AND_ASSIGN(Sha1Hash);
    };

}}

#endif /* NODECPP_CRYPTO_SHA1_H_ */
